import http from '@/utils/http'

export const loginByMailAPI = ({ email, passwd, rememberMe }) =>
  http.post('/api/user/login', {
    email,
    passwd,
    rememberMe
  })
export const loginByUsernameAPI = ({ username, passwd, rememberMe }) =>
  http.post('/api/user/login', {
    username,
    password: passwd,
    rememberMe
  })

export const registerAPI = ({ email, passwd, username }) =>
  http.post('/api/user/register', {
    email,
    passwd,
    username
  })

export const getCurrUserInfoAPI = () => http.get('/api/user')
export const logoutAPI = () => http.get('/api/user/logout')
export const checkLoginAPI = () => http.get('/api/user/checkLogin')
export const getUserInfoByIdAPI = (id) => http.get(`/api/user/${id}`)

export const getUserInfoByNameAPI = (name) => http.get(`/api/user/name/${name}`)

export const getUserRankListAPI = () => http.get('/api/user/rank')

export const getStaffListAPI = () => http.get('/api/user/staff')

export const changeUserPasswordAPI = ({ id, rawPasswd, newPasswd, newPasswdConfirm }) =>
  http.post('/api/user/changePwd', {
    id,
    rawPasswd,
    newPasswd,
    newPasswdConfirm
  })

export const changeUserEmailAPI = ({ id, passwd, email }) =>
  http.post('/api/user/changeMail', {
    id,
    passwd,
    email
  })

export const updateUserAPI = ({ id, username, displayName, avatar, intro }) =>
  http.post('/api/user', {
    id,
    username,
    displayName,
    avatar,
    intro
  })